Skip to content

fix(types): validate script JSON boundaries - #1679

Merged
ColeMurray merged 2 commits into
mainfrom
automation/unsafe-cast-sweep-20260831
Sep 8, 2026
Merged

fix(types): validate script JSON boundaries#1679
ColeMurray merged 2 commits into
mainfrom
automation/unsafe-cast-sweep-20260831

Conversation

@open-inspect

@open-inspect open-inspect Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

This is an automated nightly unsafe-cast remediation sweep. It replaces selected unsafe TypeScript casts at external/opaque JSON boundaries with local parse-and-validate guards, following the TypeScript Coding Standards guidance for unsafe casts / parse-don't-assert and the Zod boundary-validation pattern established in PR #807. These two script-local boundaries do not justify a new dependency, so the fixes use narrow inline structural guards instead of adding a schema library at the root.

Finding Risk Cast removed Fix
scripts/cf-logs.ts Low Cloudflare telemetry await response.json() asserted as a response object Validate the success flag, optional response envelopes, and the timestamp/string fields actually consumed by formatting and summaries. Reject malformed events instead of silently dropping them; preserve optional empty event results and retain unconsumed fields in --json output.
scripts/merge-split-users.ts Medium Wrangler D1 JSON.parse(child.stdout) asserted as WranglerQueryResult[] Validate query envelopes, record rows, and optional nonnegative integer change counts. Reject malformed rows instead of turning them into an empty result. Preserve statement-failure diagnostics and enforce one result per submitted statement, including single-query verification reads.

The branch incorporates current main's user-merge CLI runner/test seam and atomic result-bearing batch behavior. No new dependency is introduced.

Verification

Check Result
npm run test:user-merge-cli Passed: 18 tests, including malformed query results, failure diagnostics, empty successful results, and positional batch results.
npm run test:cf-logs-cli Passed: 20 tests exercising the real CLI with mocked fetch, including valid formatted/raw output, optional empty results, malformed events/envelopes, and API errors.
Changed-file ESLint and Prettier Passed.
Strict TypeScript check for Cloudflare logs script/tests Passed.
git diff --check Passed.
Latest-head GitHub CI Passed for 3d4429a9c8668209f1a4230f30bec584de06ea59: lint/format (including both CLI test suites), workspace typecheck, web build, control-plane unit tests, both integration shards, web tests, bot tests, Compose smoke, and Terraform validation. Terraform Plan/Apply are expected skips.

Both CLI suites run in the TypeScript CI workflow. Tests do not access live Cloudflare services or production databases.

An additional direct strict typecheck of the user-merge script reproduces main's existing SqlStatement to { render(): string } assertion diagnostic; the JSON-boundary changes introduce no additional diagnostics in that check.


Created with Open-Inspect

@open-inspect open-inspect Bot added the automation:unsafe-cast Automated unsafe TypeScript cast remediation label Aug 31, 2026
@github-actions

Copy link
Copy Markdown

Terraform Validation Results

Step Status
Format
Init
Validate
Tests

Note: Terraform plan was skipped because secrets are not configured. This is expected for external contributors. See docs/GETTING_STARTED.md for setup instructions.

Pushed by: @open-inspect[bot], Action: pull_request

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

Terraform Validation Results

Step Status
Format
Init
Validate
Tests

Note: Terraform plan was skipped because secrets are not configured. This is expected for external contributors. See docs/GETTING_STARTED.md for setup instructions.

Pushed by: @ColeMurray, Action: pull_request

@ColeMurray ColeMurray left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 3d4429a, every changed file and CLI boundary, all discussion, and main compatibility. The follow-up preserves current atomic merge safeguards, validates consumed telemetry fields without dropping raw output fields, and rejects malformed Wrangler rows instead of treating them as missing results. Both original findings remain relevant. All 38 CLI regression tests and exact-head CI passed; Terraform deployment jobs are intentionally skipped. No actionable review comments or remaining blockers.

@ColeMurray
ColeMurray merged commit 155308e into main Sep 8, 2026
13 checks passed
@ColeMurray
ColeMurray deleted the automation/unsafe-cast-sweep-20260831 branch September 8, 2026 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation:unsafe-cast Automated unsafe TypeScript cast remediation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants